<dom-module id="amp-w-setting">
    <style>
        .amp-wf-setting{
            position: absolute;
            width: 78px;
           /*  top: 36px;
           right: -22px; */
            top: 34px;
            right: 0px; 
            padding: 4px 0;
            background-color: #fff;

            -webkit-transform: scale(0);     /* for Chrome || Safari */
            -moz-transform: scale(0);        /* for Firefox */
            -ms-transform: scale(0);         /* for IE */
            -o-transform: scale(0);          /* for Opera */


           /*  -webkit-transform: scale(0); */
            transform: scale(0);
            -webkit-transform-origin: top left;
            transform-origin: top left;

            -moz-transform-origin: top left;
            -ms-transform-origin: top left;
            -o-transform-origin: top left;
            z-index:999999999;


        }

        .amp-wf-setting.amp-active{
            -webkit-transform: scale(1);
            transform: scale(1);

            -moz-transform: scale(1);
            -ms-transform: scale(1);
            -o-transform: scale(1);


        }
    </style>


    <template>
        <div class="amp-wf-setting amp-color-gray-lv1 amp-animate-trans-fast" on-click="setting">
            <content></content>
          <!--   <template is="dom-if" if="{{flag}}" >
              <amp-w-setting-item amp-w-role="openapp">打开应用</amp-w-setting-item>
          </template> -->
            <amp-w-setting-item amp-w-role="delete" class="deleteCard">@deleteCard</amp-w-setting-item>
        </div>
    </template>
    <script>
        Polymer({
            is: 'amp-w-setting',
            properties: {

            },
            setting: function (e) {
                var $target = $(e.target || e.srcElement);
                var $item = $target.closest('amp-w-setting-item');
                if($item.attr('amp-w-role') === 'delete'){
                    var $widget = $target.closest('.amp-widget');
                    var widgetId = $widget.children()[0].localName;
                    var desktopId = $widget.parent('.amp-tab-content-item').attr('amp-desktop-id');
                    var desktopType = $widget.parent('.amp-tab-content-item').attr('amp-desktop-type');
                    var cardWid =  $widget.attr('widget-wid');
                 /*   $widget.remove();*/

                   $widget.addClass('amp-animate-big-to-small');
                   $widget.hide(50, function() {
                        $(this).remove();
                   });

                    $('body').trigger("widgetRemove", 
                        [{widgetId: widgetId,desktopId:desktopId,desktopType:desktopType,cardWid:cardWid}]);
                }else if($item.attr('amp-w-role') === 'openapp'){
                var $apmWidget =$item.parents('.amp-widget');
                var appid = $apmWidget.attr('app-id');
                var hasHead = $item.attr('amp-hashead');
                var url = AMPConstant.requestPath+"appShow?appId=" + appid;
                var appkey = $apmWidget.attr('app-key');

                //数据分析发送请求
                var sendschoolID = AMPConfigure.schoolId;
                var senduserID = parent.window.AmpUtils.getSessionStorageData("ampUserID");
                var senduserIp = parent.window.AmpUtils.getSessionStorageData("ampUserIp");
                var sendappKey = appkey;
                
                parent.window.Wisedu.userActionDataSend();
                Wisedu.ampAppDataSend(sendschoolID, senduserID, senduserIp, sendappKey, "appShow");

               if (hasHead == '1') { //有head
                  window.open(url);
                } else if (hasHead == '0') { //没有head  //参数1 url   参数2 是否有head  参数3 appID  参数4 appName
                    var noHeadUrl = AMPConstant.requestPath + "new/indexShell.html";
                    localStorage.openHasNoHeadAppUrl = url;
                    localStorage.openHasNoHeadAppId = appId;
                    localStorage.openHasNoHead = '0';
                    localStorage.openHasNoHeadTitle = title;
                    window.open(noHeadUrl);
                } else {
                   window.open(url);
                }  

                }
            },
            ready: function() {
 
            }
        });
    </script>
</dom-module>